//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_startclientscripts.sqf"
#include "x_setup.sqf"

if (!alive player || {(player getVariable 'xr_pluncon')}) exitWith {};
private ["_vec", "_type", "_wtime", "_minutes"];
if (!(GVAR(clientScriptsAr) select 0) && {(isMultiplayer && {serverCommandAvailable "#shutdown"}) || {!isMultiplayer}} && {alive player} && {!(player getVariable 'xr_pluncon')}) then {
	GVAR(clientScriptsAr) set [0, true];
	__pSetVar [QGVAR(p_isadmin), true];
	execFSM "fsms\isAdmin.fsm";
};
if (!(GVAR(clientScriptsAr) select 1) && {!isNil QGVAR(player_autokick_time)}) then {
	//TYRGHEN
	if (if (isnil "mp_rights_fnc_hasRoles") then {false} else {([] call mp_rights_fnc_isRecruit)}) exitWith {};

	if (isNil QGVAR(nomercyendtime)) then {
		GVAR(nomercyendtime) = time + GVAR(player_autokick_time);
		if (GVAR(player_autokick_time) <= 0) exitWith {
			GVAR(clientScriptsAr) set [1, true];
			GVAR(player_autokick_time) = nil;
			GVAR(nomercyendtime) = nil;
		};
	} else {
		if (time >= GVAR(nomercyendtime)) exitWith {
			GVAR(clientScriptsAr) set [1, true];
			GVAR(player_autokick_time) = nil;
			GVAR(nomercyendtime) = nil;
		};
		_vec = vehicle player;
		if (_vec != player && {_vec isKindOf "Air"}) then {
			_type = typeOf _vec;
			if ((toUpper(_type) in GVAR(mt_bonus_vehicle_array) || {toUpper(_type) in GVAR(sm_bonus_vehicle_array)}) && {(player == driver _vec || {player == gunner _vec} || {player == commander _vec})}) then {
				_was_engineon = isEngineOn _vec;
				player action ["Eject",_vec];
				if (!_was_engineon && {isEngineOn _vec}) then {
					_vec engineOn false;
					player action ["engineOff", _vec];
				};
				_type_name = [_type,0] call FUNC(GetDisplayName);
				_wtime = GVAR(nomercyendtime) - time;
				_minutes = round (_wtime / 60);
				if (_minutes < 1) then {_minutes = 1};
				[format [localize "STR_DOM_MISSIONSTRING_1416", _type_name, _minutes], "HQ"] call FUNC(HintChatMsg);
			};
		};
	};
};